//
//  SingieViewController.m
//  UIPickerViewDemo
//
//  Created by student on 16/2/23.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "SingieViewController.h"

@interface SingieViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>

@property (nonatomic,strong) NSArray *list;

@end

@implementation SingieViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.UIPickerView.dataSource = self;
    self.UIPickerView.delegate = self;
    
    self.list = @[@"张三",@"李四",@"王五",@"赵六",@"胖胖"];
}
//通过代理洗衣的方式为UIPickerView提供数据

#pragma mark UIPickerViewDataSourceDelegate Method
//方法
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;//当前就1列 就返回这1列的内容
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return self.list.count;//从当期6行中选择，然后返回这6行中选择的
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    return self.list[row];//打印选择的
}



- (IBAction)btnPressed:(id)sender
{
    int sel = [self.UIPickerView selectedRowInComponent:0];
    NSString *name = self.list[sel];//通过第几项
    //弹出选择结果的提示框
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"选择了谁？" message:name delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alert show];
}







//通过代理洗衣的方式为UIPickerView提供数据

#pragma mark UIPickerViewDataSourceDelegate Method



//选择pickerView的内容的时候触发的事件

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.UILabel.text = self.list[row];
}




@end
